(function() {
    'use strict';

    angular
        .module('milkbeeApp')
        .controller('CommentDetailController', CommentDetailController);

    CommentDetailController.$inject = ['$scope', '$rootScope', '$stateParams', '$http','previousState', 'entity', 'Comment'];

    function CommentDetailController($scope, $rootScope, $stateParams,$http, previousState, entity, Comment) {
        var vm = this;

        vm.comment = entity;
        vm.previousState = previousState.name;
        vm.leaguermap={};
        vm.categorymap={};
        
        var unsubscribe = $rootScope.$on('milkbeeApp:commentUpdate', function(event, result) {
            vm.comment = result;
        });
        $scope.$on('$destroy', unsubscribe);
        
        function loadLeaguers(){
        	$http({
        		method: 'get',
        		url: '/api/allleaguers',
        		transformRequest: angular.identity
        	}).success(function(ret){
        		vm.leaguers=ret;
        		for(var i=0; i<vm.leaguers.length; i++) {
        			vm.leaguermap[vm.leaguers[i].id]=vm.leaguers[i].name;
        		}
        		//console.log(vm.leaguermap);
        	});
        }
        function loadCategories(){
        	$http({
        		method: 'get',
        		url: '/api/categoriesbylevel/1',
        		transformRequest: angular.identity
        	}).success(function(ret){
        		vm.categories=ret;
        		for(var i=0; i<vm.categories.length; i++) {
        			vm.categorymap[vm.categories[i].id]=vm.categories[i].name;
        		}
        	});
        }
        loadLeaguers();
        loadCategories();
    }
})();
